import java.util.Scanner;

public class gameinterface {
	static Player player[];
	static Deck deck;
	static int temp;
	static float temp2;
	
	public static void main(String[] args) {
	
		
		Scanner in = new Scanner(System.in);
		System.out.println(" Please Enter total amount of Player ");
		 player = new Player[in.nextInt()];

		for(int i = 0;i <player.length;i++)
		{
			player[i] = new Player();
		}
		
		System.out.println("what player is banker?");
		
		player[in.nextInt() -1].isbanker = true;

		
		deck = new Deck();
		
		
		deck.shuffle();
		deck.makePile();
		
	
		for(int i = 0;i <player.length;i++)
		{
			
		System.out.println(player[i].playername+" , Please choose from pile ( 1 - "+(deck.pilelist.length-1)+" )");
		do
		{
			 temp = in.nextInt();
		} while(temp > (deck.pilelist.length-1 )  || temp <=0 );
		
		player[i].choosenpile = temp;
		
		
		if (player[i].isbanker == false)
		{
			
			System.out.println(player[i].playername+" , please make your bet ($.01 - $"+player[i].balance+")");
			
			do 
				{
				temp2 = in.nextFloat();
				}
		    	while(temp2 > player[i].balance || temp2<=0 );
			
			player[i].betamount = temp2;
		}
	
		
		
		}
		
		calculateWinner();
		
	}
	
	 static void calculateWinner()
	{
		
		  int banker  = calculateFinalScore();
		 
		 for (int i = 0;i<player.length;i++)
		 {
			 if (player[i] != player[banker])
			 {
				 if (player[i].finalscore <= player[banker].finalscore)
				 {
					 player[i].balance =  player[i].balance-player[i].betamount;
					 player[banker].balance =  player[banker].balance+player[i].betamount;
					 
					 System.out.println( player[i].playername +" got card "+deck.toCardName(player[i].finalscore) +" , has bet $"+player[i].betamount + " and LOSE . Now he has $"+player[i].balance  );
					 
				 } 
				 else if (player[i].finalscore > player[banker].finalscore)
				 {
					 player[i].balance =  player[i].balance+player[i].betamount;
					 player[banker].balance =  player[banker].balance-player[i].betamount;
					 
					 System.out.println( player[i].playername +" got card "+deck.toCardName(player[i].finalscore) +" , has bet $"+player[i].betamount + " and WON . Now he has $"+player[i].balance  );
				 }
				 
				 else
					 System.out.println("calculation error! , I donno wtf's going on");
				 

			 }
			 
			 
			 
			 
		 }
	
		 System.out.println( player[banker].playername +" got card "+deck.toCardName(player[banker].finalscore) +".		         Now he has $"+player[banker].balance  );// gets banker summary
		
		 
		 
		 // gets all card detail
		 
		 
		
		
		
	}
	
	 static int  calculateFinalScore()
	{
		int thisbanker = -1;
		
		for(int i = 0;i<player.length;i++)
			{
		
			
			if (player[i].isbanker == true)
			{
				
				thisbanker = i;
				
			}
				
				
			player[i].finalscore =  Integer.parseInt(deck.pilelist[player[i].choosenpile]) ;
			}
		
		return thisbanker;
	}
	
	



}
